//
//  NetEasyCell.m
//  Together
//
//  Created by Wang Shuguang on 12-12-17.
//  Copyright (c) 2012年 Dawn. All rights reserved.
//

#import "NetEasyCell.h"
#import "UIImageView+WebCache.h"

@implementation NetEasyCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        separateView = [[UIImageView alloc] initWithFrame:CGRectMake(6, 0, SCREEN_WIDTH - 12, 2)];
        separateView.image = [UIImage imageNamed:@"category_separate_light.png"];
        [self addSubview:separateView];
        [separateView release];
        
        UIImageView *seleBgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 71)];
        seleBgView.clipsToBounds = YES;
        seleBgView.contentMode = UIViewContentModeTop;
        seleBgView.image = [UIImage imageNamed:@"category_cellhighlighted_bg.png"];
        self.selectedBackgroundView = seleBgView;
        [seleBgView release];
        
        // 图片
        newsImageView= [[UIImageView alloc] initWithFrame:CGRectMake(6, 10, 70, 52)];
        newsImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:newsImageView];
        [newsImageView release];
        
        // 新闻标题
        titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(90, 10, SCREEN_WIDTH - 10 - 90, 20)];
        titleLbl.font = [UIFont systemFontOfSize:14.0f];
        titleLbl.textColor = [UIColor colorWithRed:33.0/255.0f green:33.0f/255.0f blue:33.0/255.0f alpha:1.0];
        [self addSubview:titleLbl];
        [titleLbl setBackgroundColor:[UIColor clearColor]];
        [titleLbl release];
        
        // 简介
        tipsLbl = [[UILabel alloc] initWithFrame:CGRectMake(90, 28, SCREEN_WIDTH - 10 - 90, 16 * 2)];
        tipsLbl.font = [UIFont systemFontOfSize:12.0f];
        tipsLbl.textColor = [UIColor colorWithRed:120.0/255.0f green:120.0f/255.0f blue:120.0/255.0f alpha:1.0];
        tipsLbl.numberOfLines = 2;
        [self addSubview:tipsLbl];
        [tipsLbl setBackgroundColor:[UIColor clearColor]];
        [tipsLbl release];
        
        // 发布时间
        pubLbl = [[UILabel alloc] initWithFrame:CGRectMake(90, 70-14, SCREEN_WIDTH - 10 - 90, 14)];
        pubLbl.font = [UIFont systemFontOfSize:12.0f];
        pubLbl.textColor = [UIColor colorWithRed:120.0/255.0f green:120.0f/255.0f blue:120.0/255.0f alpha:1.0];
        [self addSubview:pubLbl];
        pubLbl.textAlignment = UITextAlignmentRight;
        [pubLbl setBackgroundColor:[UIColor clearColor]];
        [pubLbl release];

    }
    return self;
}

- (void) setNewsImageWithURL:(NSURL *)url{
    if (url) {
        [newsImageView setImageWithURL:url placeholderImage:nil options:SDWebImageLowPriority];
        titleLbl.frame = CGRectMake(90, titleLbl.frame.origin.y, SCREEN_WIDTH - 10 - 90, 20);
        tipsLbl.frame = CGRectMake(90, tipsLbl.frame.origin.y, SCREEN_WIDTH - 10 - 90, 16 *2);
    }else{
        newsImageView.image = nil;
        titleLbl.frame = CGRectMake(10, titleLbl.frame.origin.y, SCREEN_WIDTH - 20, 20);
        tipsLbl.frame = CGRectMake(10, tipsLbl.frame.origin.y, SCREEN_WIDTH - 20, 16 *2);
    }

}

- (void) setTitle:(NSString *)title{
    titleLbl.text = title;
}

- (void) setTips:(NSString *)tips{
    tipsLbl.text = tips;
}

- (void) setPub:(NSString *)pub{
    pubLbl.text = pub;
}

- (void) setSeparateViewHidden:(BOOL)hidden{
    separateView.hidden = hidden;
    separateHidden = hidden;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
    
    if (selected) {
        separateView.hidden = YES;
    }else{
        separateView.hidden = (NO || separateHidden);
    }
    
}

- (void) setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setHighlighted:highlighted animated:animated];
    if (highlighted) {
        separateView.hidden = YES;
    }else{
        separateView.hidden = (NO || separateHidden);
    }
}


@end
